﻿using FineCollection.Test;

using NUnit.Framework;

namespace FineCollection.Const
{


    [TestFixture]
    public class ConstList_test
    {

        #region BASIC

        [Test]
        public void Test_Basic0()
        {
            ConstList<long> list = CC1.ListOf(new long[0]);
            
            list.Count      ._equals_(0);
            list.IsEmpty    ._equals_(true);
            list.IsNotEmpty ._equals_(false);
        }


        [Test]
        public void Test_Basic1()
        {
            ConstList<long> list = CC1.ListOf(1111L);
            
            list.Count      ._equals_(1);
            list.IsEmpty    ._equals_(false);
            list.IsNotEmpty ._equals_(true);

            list[1]         ._equals_(1111L);
        }


        [Test]
        public void Test_Basic3()
        {
            ConstList<long> list = CC1.ListOf(444L, 777L, 999L);

            list[1] ._equals_(444L);
            list[2] ._equals_(777L);
            list[3] ._equals_(999L);
        }


        #endregion



        #region HASH CODE

        [Test]
        public void Test_HashCodeWithNull()
        {
            var a = CC0.ListOf("tea", null, "coffee");

            a.GetHashCode(); // it should not throw exeptions
        }


        #endregion



        #region EQUALS

        [Test]
        public void Test_EqualsBasic()
        {
            var a = CC1.ListOf(444L, 666L, 777L, 999L);
            var b = CC1.ListOf(444L, 666L, 777L, 999L);

            (a == b) ._true_();
            (a != b) ._false_();
        }


        [Test]
        public void Test_EqualsSame()
        {
            var a = CC1.ListOf(444L, 666L);
            var b = a;

            (a == b) ._true_();
            (a != b) ._false_();
        }


        [Test]
        public void Test_EqualsDifferentFirstIndices()
        {
            var a = CC1.ListOf(444L, 666L);
            var b = CC0.ListOf(444L, 666L);

            (a == b) ._false_();
            (a != b) ._true_();
        }


        [Test]
        public void Test_EqualsWithNull()
        {
            var a = CC0.ListOf("tea", null, "coffee");
            var b = CC0.ListOf("tea", null, "coffee");

            (a == b) ._true_();
            (a != b) ._false_();
        }


        [Test]
        public void Test_EqualsNull()
        {
            var a = CC0.ListOf(111L);
            ConstList<long> b = null;

            (a == b) ._false_();
            (a != b) ._true_();
        }


        #endregion



        #region DEBUG VIEW

        [Test]
        public void Test_DebugView_0()
        {
            ConstList<long> list = CC1.ListOf<long>();

            var debugView = new ConstArrayDebugView<long>(list);
            var debugItems = debugView.Items;

            debugItems.Length  ._equals_(0);
        }


        [Test]
        public void Test_DebugView_3()
        {
            ConstList<long> list = CC1.ListOf(555L, 777L, 999L);

            var debugView = new ConstArrayDebugView<long>(list);
            var debugItems = debugView.Items;

            debugItems.Length  ._equals_(3);
            debugItems         ._array_(555L, 777L, 999L);
        }

        #endregion

    }


}